package com.owlab.dcs;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
	private String comServerLocation = null; // IP address or Host name
	private int comServerPort = 50010;	// the port number server listening
	private Socket socket = null;
	private BufferedReader in = null;
	private PrintWriter out = null;

	public Client(String serverLocation, int serverPort) {
		this.comServerLocation = serverLocation;
		this.comServerPort = serverPort;
	}

	public String makeCall(String request){
		String response = null;
		try {
			socket = new Socket(comServerLocation, comServerPort);
			out = new PrintWriter(socket.getOutputStream(),true);
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));


			// send a message to the server
			out.println(request);
			// wait & receive a reply from the server
			response = in.readLine();

			in.close();
			out.close();
			socket.close();

		}catch(Exception e){
			System.out.println(e);
			System.exit(-1);
		}
		return response;
	}

}
